#!/usr/bin/env bash

#安装mariadb
yum -y install mariadb mariadb-server

systemctl start mariadb
systemctl enable mariadb

#初始化
mariadb-secure-installation
#输入当前用户的口令         enter(回车)
#Enter current password for root (enter for none):
#切换到unix_socket身份验证
#Switch to unix_socket authentication [Y/n] n
#更改初始化密码
#Change the root password? [Y/n] y
#移除匿名账号
#Remove anonymous users? [Y/n] y
#为了实验方便，允许root账号的远程访问
#Disallow root login remotely? [Y/n] n
#移除test数据库
#Remove test database and access to it? [Y/n] y
#设置是否生效
#Reload privilege tables now? [Y/n] y

#登录
#修改密码后，使用centos非root账号登陆mysql需要输入密码。
mysql -u root -p $password

CREATE DATABASE IF NOT EXISTS mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

GRANT ALL PRIVILEGES ON mydatabase.* TO 'newuser'@'%' IDENTIFIED BY 'password123';
FLUSH PRIVILEGES;

#退出修改my.cnf或者mariadb-server.cnf
[mysqld]
port=3333
default-time_zone = '+8:00'
character_set_server=utf8mb4
init_connect='SET NAMES utf8mb4'